/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.transas.zorlog.data.log;

import com.transas.zorlog.data.DataSource;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingWorker;

/**
 * Saves values from the given DataSource to text file.
 * @author amalikov
 */
public class LogSaverWorker extends SwingWorker<Void, Void> {
	
	public LogSaverWorker(String logFileName, String formatName, DataSource ds) {
		if ("Text log".equalsIgnoreCase(formatName))
			saver = new TextLogSaver(logFileName, ds);
		else if ("Google Earth KML".equalsIgnoreCase(formatName))
			saver = new KmlLogSaver(logFileName, ds);
		else
			saver = null;		
	}
	
	@Override
	protected Void doInBackground() throws Exception {
		try {
			saver.write(new ProgressInformer(){
				@Override
				public void set(int value) {
					setProgress(value);
				}
			});

		} catch (IOException ex) {
			Logger.getLogger(PacketReader.class.getName()).log(Level.SEVERE, null, ex);
		}
		
		return null;
	}

	private LogSaver saver;
}

